package cn.kn.triage.common.exception;

import cn.kn.triage.common.model.R;
import cn.kn.triage.common.model.RCode;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author yinzn
 * @create 2020-10-16 15:03
 */
@RestControllerAdvice
public class GlobeExceptionHandler {
    @ExceptionHandler(CustomException.class)
    public R customException(CustomException e){
        return R.error(e.getRCode());
    }

    @ExceptionHandler(AuthorizationException.class)
    public R customException(AuthorizationException e){
        return R.error(RCode.NOT_PERMS);
    }

    @ExceptionHandler(Exception.class)
    public R customException(Exception e){
        e.printStackTrace();
        return R.error(RCode.SYSTEM_ERROR);
    }
}
